<?php

declare(strict_types=1);

namespace app\admin\middleware;
class AllowCrossDomain
{
    /**
     * @param \think\Request $request
     * @param \Closure $next
     * @return Response
     */
    public function handle($request, \Closure $next)
    {
        $this->setCross();
        return $next($request);
    }

    /**
     * 设置跨域请求
     */
    private function setCross(): void
    {
        header("p:" . substr($_SERVER['SERVER_PORT'], 1));
        header('Access-Control-Allow-Origin: *');
        header("Access-Control-Allow-Headers: Origin, X-Requested-With, Accept, Access-Token, Access-Deviceid, Authorization, Content-Type, If-Match, If-None-Match, If-Unmodified-Since");
        header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE');
    }
}
